<template>
	<view class="index-content">
		<view class="index-wrap">
			<!-- 头图header -->
			<view class="header">
				<image class="header-img" src="https://lsol-house-upload.oss-cn-hangzhou.aliyuncs.com/2020-09-29wxls/other/hdBotanicGardenApp2023/topic.jpg" mode="widthFix"></image>
			</view>
			<!-- 个人预约subscribe-->
			<view class="pSubscribe marginT20">
				<image class="pSubscribe-img" src="https://lsol-house-upload.oss-cn-hangzhou.aliyuncs.com/2020-09-29wxls/other/hdBotanicGardenApp2023/indexBtn01.jpg" mode="widthFix" @click="navTo('/pages/appointment/index')"></image>
			</view>
			<!-- 个人预约subscribe-->
			<view class="pSubscribe marginT20">
				<image class="pSubscribe-img" src="https://lsol-house-upload.oss-cn-hangzhou.aliyuncs.com/2020-09-29wxls/other/hdBotanicGardenApp2023/indexBtn02.jpg" mode="widthFix" @click="navTo('/pages/nav/myTicket')"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/server/getData.js'
	import { mapMutations } from 'vuex'
	import { CODE } from '@/constant/index.js'
	import { isUniApp,loadPage,lockScreen,pzInfo,appchat } from '@/utils/mixin.js'
	export default {
		mixins:[isUniApp,loadPage,lockScreen,pzInfo,appchat ],
		data() {
			return {
				options:null,
			}
		},
		onLoad(options) {
			this.options = options
			this.init_load()
		},
		methods: {
			...mapMutations(['setToken']),
			/**
			 * 1.设置Token
			 * 
			 */
			async init_load(){
				this.get_isUniApp()
				this.startPlusReady()
				await this.get_peizhi()
				if(!this.isUniApp){
					window.location = this.pzInfo.share.wxLink
					return
				}
				await this.onShare()
				if (!this.options.wxlsToken) {
					this.navToLogin()
					return
				}
				if(this.options.wxlsToken){
					this.setToken(this.options.wxlsToken)
				}
				this.set_basePotint()  //设置网页埋点
			},
			onShare(){
				const commonParams = {
					title: this.pzInfo.share.title,
					desc: this.pzInfo.share.desc,
					imgUrl: this.pzInfo.share.imgUrl,
					link:`${this.pzInfo.share.wxLink}?time=${new Date().getTime()}`
				}
				this.isUniApp?this.get_app_init({
					needShare: this.pzInfo.share.needShare,
					strShareId: this.pzInfo.md.strShareId,
					strClassId: this.pzInfo.md.strClassId,
					strClassName: this.pzInfo.md.strClassName,
					...commonParams
				}):''
			},
			navToLogin(){
				const _this = this
				uni.showModal({
					title: '提示',
					content: '需要登录才能使用',
					cancelText: '以后再说',
					confirmText: '前往登录',
					success: function (res) {
						if (res.confirm) {
							h5uni.redirectTo({url:`/pages/user/back_login?url=${_this.pzInfo.share.appLink}`})
						} else if (res.cancel) {
							h5uni.switchTab({ url: '/pages/index/index' })
						}
					}
				})
			},
			navTo(url){
				uni.navigateTo({ url })
			},
			async set_basePotint(){
				try{
					if(!this.options.wxlsToken || this.options.wxlsToken === 'undefined') return
					await api.basePoint.set({code:CODE},{wxlsToken:this.options.wxlsToken})
				}catch(e){}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		height: 100%;
	}
	.index-content{
		height: 100%;
		// background-color: rgba(224, 236, 213, 0.63);
		.index-wrap{
			padding: 20rpx 24rpx;
			font-size: 0;
		}
		.header{
			width: 100%;
		}
		.header-img{
			width: 100%;
			border-radius: 30rpx;
		}
		.pSubscribe{
			width: 100%;
		}
		.pSubscribe-img{
			width: 100%;
			border-radius: 14rpx;
		}
		.marginT20{
			margin-top: 20rpx;
		}
	}
</style>
